// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import BirdControl from "./bridControl";

const {ccclass, property} = cc._decorator;

@ccclass
export default class BgControl extends cc.Component {

    @property
    speed: number = 4;

    @property
    width: number = 288;

    @property(BirdControl)
    birdControl: BirdControl = null;

    // onLoad () {}

    start() {
        if(this.birdControl != null){
            for (let bg of this.node.children) {
                bg.on(cc.Node.EventType.MOUSE_DOWN, () => {
                    this.birdControl.fly();
                })
            }
        }
    }

    update(dt) {
        for (let bg of this.node.children) {
            bg.x -= this.speed * dt;
            if (bg.x < -this.width) {
                bg.x += this.width * 2;
            }
        }
    }
}
